package com.jerry.constellation.Adapter;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jerry.constellation.R;

import java.util.List;

public class LuckyDetialsAdapter extends BaseAdapter {
    private Context mcontext;
     private List<LuckyDetialsItemBean> mdata;

    public LuckyDetialsAdapter(Context context, List<LuckyDetialsItemBean> data) {
        this.mcontext = context;
        this.mdata = data;
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return mdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if (view==null) {
            view= LayoutInflater.from(mcontext).inflate(R.layout.lucky_detials_lv_item,null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        LuckyDetialsItemBean bean = mdata.get(i);
        viewHolder.title.setText(bean.getTitle());
        viewHolder.content.setText(bean.getContent());
        //改变textview的背景颜色
        GradientDrawable drawable= (GradientDrawable) viewHolder.title.getBackground();
        drawable.setColor(bean.getColorid());
        return view;
    }

    class ViewHolder{
        TextView title;
        TextView content;
        public  ViewHolder(View view){
            title=view.findViewById(R.id.lucky_detials_Lv_item_title);
            content=view.findViewById(R.id.lucky_detials_Lv_item_content);
        }
    }
}
